/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package almacen;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author Tesla
 */
public class Precios extends javax.swing.JDialog {

    /**
     * Creates new form Precios
     */
      Connection cn;
    PreparedStatement ps;
    ResultSet rs;
    static int code;
    public Precios(java.awt.Frame parent, boolean modal,int cd) {
        super(parent, modal);
        initComponents();
        preciocompra.setDocument(new LimitadorCaracteresFloat());
        precio_unitario.setDocument(new LimitadorCaracteresFloat());
        precio_mayoreo.setDocument(new LimitadorCaracteresFloat());
        cantidad_medio.setDocument(new LimitadorCaracteres());
        cantidad_mayoreo.setDocument(new LimitadorCaracteres());
        code = cd;
        try {
            cn = local_connection.getconnect();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        cargarPrecios();
        sugerenciasMayoreos();
    }  class LimitadorCaracteresFloat extends PlainDocument
{
   /**
    * Método al que llama el editor cada vez que se intenta insertar caracteres.
    * Sólo debemos verificar arg1, que es la cadena que se quiere insertar en el JTextField
    */
   public void insertString(int arg0, String arg1, AttributeSet arg2) throws BadLocationException
   {
       for (int i=0;i<arg1.length();i++)
          // si no es digit, volvemos
          if (!(Character.isDigit(arg1.charAt(i))||arg1.charAt(i)=='.'))
             return;

       // Si todos son digit, insertamos el texto en el JTextField
       super.insertString(arg0, arg1, arg2);
   }
      }
    class LimitadorCaracteres extends PlainDocument
{
   /**
    * Método al que llama el editor cada vez que se intenta insertar caracteres.
    * Sólo debemos verificar arg1, que es la cadena que se quiere insertar en el JTextField
    */
   public void insertString(int arg0, String arg1, AttributeSet arg2) throws BadLocationException
   {
       for (int i=0;i<arg1.length();i++)
          // si no es digit, volvemos
          if (!Character.isDigit(arg1.charAt(i)))
             return;

       // Si todos son digit, insertamos el texto en el JTextField
       super.insertString(arg0, arg1, arg2);
   }
} 
void cargarPrecios(){
    float precio;
    int porcentaje;
          try {
              ps =   (PreparedStatement) cn.prepareStatement("SELECT preciocompra, precio_unitario, cantidad_medio, precio_medio, cantidad_mayoreo, precio_mayoreo, precio_distribuidor, cantidad_distribuidor FROM productos WHERE id_producto = "+code);
                  rs = ps.executeQuery();
                  rs.next();
                  preciocompra.setText(rs.getString("preciocompra"));
                  precio_unitario.setText(rs.getString("precio_unitario"));
                  cantidad_medio.setText(rs.getString("cantidad_medio"));
                  precio_medio.setText(rs.getString("precio_medio"));
                  cantidad_mayoreo.setText(rs.getString("cantidad_mayoreo"));
                  precio_mayoreo.setText(rs.getString("precio_mayoreo"));
                  cantidad_distribuidor.setText(rs.getString("cantidad_distribuidor"));
                  precio_distribuidor.setText(rs.getString("precio_distribuidor"));
                  // Calculamos el procentaje que va en el dropbox
                  precio = Float.parseFloat(precio_unitario.getText());
                  porcentaje = (int) (100-((Float.parseFloat(precio_medio.getText())*100)/precio));
                  jComboBox3.setSelectedIndex(getIndex(porcentaje));
                  porcentaje = (int) (100-((Float.parseFloat(precio_mayoreo.getText())*100)/precio));
                  jComboBox4.setSelectedIndex(getIndex(porcentaje));
                  porcentaje = (int) (100-((Float.parseFloat(precio_distribuidor.getText())*100)/precio));
                  jComboBox1.setSelectedIndex(getIndex(porcentaje));
                  
          } catch (SQLException ex) {
              Logger.getLogger(Precios.class.getName()).log(Level.SEVERE, null, ex);
          }
}
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        cantidad_mayoreo = new javax.swing.JTextField();
        cantidad_medio = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel34 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        precio_mayoreo = new javax.swing.JTextField();
        jLabel31 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        precio_unitario = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        preciocompra = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        precio_medio = new javax.swing.JTextField();
        jLabel33 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        precio_distribuidor = new javax.swing.JTextField();
        cantidad_distribuidor = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Precios");
        setIconImage(new ImageIcon(getClass().getResource("logo_rayito.png")).getImage());
        setResizable(false);

        jLabel27.setText("+");

        jLabel28.setText("+ 1");

        jLabel30.setText("$");

        cantidad_mayoreo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cantidad_mayoreoActionPerformed(evt);
            }
        });

        jLabel25.setText("Mayoreo: ");

        jLabel26.setText("+");

        jLabel29.setText("$");

        jButton3.setText("Salir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel34.setText("0");

        jButton2.setText("Guardar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        precio_mayoreo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                precio_mayoreoActionPerformed(evt);
            }
        });

        jLabel31.setText("$");

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "5%", "10%", "15%", "20%", "25%", "30%" }));
        jComboBox4.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBox4PopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });
        jComboBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox4ActionPerformed(evt);
            }
        });

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "5%", "10%", "15%", "20%", "25%", "30%" }));
        jComboBox3.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBox3PopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });

        precio_unitario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                precio_unitarioActionPerformed(evt);
            }
        });
        precio_unitario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                precio_unitarioKeyReleased(evt);
            }
        });

        jLabel32.setText("0");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "20%", "30%", "50%", "100%", "150%", "200%", "250%", "300%", "350%", "400%", "450%" }));
        jComboBox2.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBox2PopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        preciocompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                preciocompraActionPerformed(evt);
            }
        });
        preciocompra.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                preciocompraKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                preciocompraKeyReleased(evt);
            }
        });

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel21.setText("Precio al Publico:");

        precio_medio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                precio_medioActionPerformed(evt);
            }
        });

        jLabel33.setText("0");

        jLabel23.setText("Unitario:");

        jLabel24.setText("Medio-May:");

        jLabel22.setText("Sugerencias:");

        jLabel20.setText("Precio de compra: $");

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel19.setText("Precios:");

        jLabel1.setText("Distribuidor:");

        cantidad_distribuidor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cantidad_distribuidorActionPerformed(evt);
            }
        });

        jLabel2.setText("+");

        jLabel3.setText("$");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "5%", "10%", "15%", "20%", "25%", "30%" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel4.setText("0");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel20)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(preciocompra, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel24, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel25, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel23, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel27)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cantidad_medio, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel28, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel26)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cantidad_distribuidor, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cantidad_mayoreo, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel29)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(precio_unitario))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(precio_distribuidor))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel31)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(precio_mayoreo, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel30)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(precio_medio, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(0, 0, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBox4, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jButton2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel33, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel32, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel34, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel4))
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(34, 34, 34))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel22)
                        .addGap(54, 54, 54))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(preciocompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jLabel22))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jLabel28)
                    .addComponent(jLabel29)
                    .addComponent(precio_unitario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel32))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(jLabel27)
                    .addComponent(cantidad_medio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel30)
                    .addComponent(precio_medio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel33))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(jLabel26)
                    .addComponent(cantidad_mayoreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel31)
                    .addComponent(precio_mayoreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel34))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cantidad_distribuidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(precio_distribuidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addGap(18, 18, 18))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cantidad_mayoreoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cantidad_mayoreoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cantidad_mayoreoActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
          try {
              ps=(PreparedStatement)cn.prepareStatement("UPDATE productos set preciocompra = ?, precio_unitario = ?, cantidad_medio = ?, precio_medio = ?, cantidad_mayoreo = ?, precio_mayoreo = ?, cantidad_distribuidor = ?, precio_distribuidor = ? where id_producto = ?");
              ps.setFloat(1, Float.parseFloat(preciocompra.getText()));
              ps.setFloat(2, Float.parseFloat(precio_unitario.getText()));
              ps.setInt(3, Integer.parseInt(cantidad_medio.getText()));
              ps.setFloat(4, Float.parseFloat(precio_medio.getText()));
              ps.setInt(5, Integer.parseInt(cantidad_mayoreo.getText()));
              ps.setFloat(6, Float.parseFloat(precio_mayoreo.getText()));
              ps.setInt(7, Integer.parseInt(cantidad_distribuidor.getText()));
              ps.setFloat(8, Float.parseFloat(precio_distribuidor.getText()));
              ps.setInt(9,code);
              ps.execute();
              this.dispose();
                      // TODO add your handling code here:
          } catch (SQLException ex) {
              Logger.getLogger(Precios.class.getName()).log(Level.SEVERE, null, ex);
          }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void precio_mayoreoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_precio_mayoreoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_precio_mayoreoActionPerformed

    private void jComboBox4PopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBox4PopupMenuWillBecomeInvisible
       sugerenciasMayoreos();
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox4PopupMenuWillBecomeInvisible

    private void jComboBox3PopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBox3PopupMenuWillBecomeInvisible
       sugerenciasMayoreos();
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox3PopupMenuWillBecomeInvisible

    private void precio_unitarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_precio_unitarioActionPerformed

        // TODO add your handling code here:
    }//GEN-LAST:event_precio_unitarioActionPerformed

    private void precio_unitarioKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_precio_unitarioKeyReleased
sugerenciasMayoreos();        
    }//GEN-LAST:event_precio_unitarioKeyReleased

    private void jComboBox2PopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBox2PopupMenuWillBecomeInvisible
      if(!precio_unitario.getText().equals("")){
        jLabel32.setText(String.valueOf(Float.parseFloat(precio_unitario.getText())+Float.parseFloat(precio_unitario.getText())*porcentajeSugerido()/100)+'0');
    }   
else jLabel32.setText("");
    }//GEN-LAST:event_jComboBox2PopupMenuWillBecomeInvisible

    private void preciocompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_preciocompraActionPerformed

        // TODO add your handling code here:
    }//GEN-LAST:event_preciocompraActionPerformed

    private void preciocompraKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_preciocompraKeyPressed

        // TODO add your handling code here:
    }//GEN-LAST:event_preciocompraKeyPressed

    private void preciocompraKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_preciocompraKeyReleased
if(!preciocompra.getText().equals("")){
    jLabel32.setText(String.valueOf(Float.parseFloat(preciocompra.getText())+Float.parseFloat(preciocompra.getText())*porcentajeSugerido()/100)+'0');
}   
else jLabel32.setText("");      
        // TODO add your handling code here:
    }//GEN-LAST:event_preciocompraKeyReleased

    private void precio_medioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_precio_medioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_precio_medioActionPerformed

    private void jComboBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox4ActionPerformed

        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox4ActionPerformed

    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox3ActionPerformed

    private void cantidad_distribuidorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cantidad_distribuidorActionPerformed
     // TODO add your handling code here:
    }//GEN-LAST:event_cantidad_distribuidorActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        sugerenciasMayoreos();
    }//GEN-LAST:event_jComboBox1ActionPerformed
void sugerenciasMayoreos(){
    if(!precio_unitario.getText().equals("")){
        jLabel33.setText(String.valueOf(Float.parseFloat(precio_unitario.getText())-Float.parseFloat(precio_unitario.getText())*porcentajeMayoreos(jComboBox3.getSelectedIndex())/100)+'0');
        jLabel34.setText(String.valueOf(Float.parseFloat(precio_unitario.getText())-Float.parseFloat(precio_unitario.getText())*porcentajeMayoreos(jComboBox4.getSelectedIndex())/100)+'0');
        jLabel4.setText(String.valueOf(Float.parseFloat(precio_unitario.getText())-Float.parseFloat(precio_unitario.getText())*porcentajeMayoreos(jComboBox1.getSelectedIndex())/100)+'0');
    }   
else jLabel33.setText("");
}
    float porcentajeMayoreos(int num){
    switch(num){
        case 1: return 10; 
        case 2: return 15; 
        case 3: return 20; 
        case 4: return 25; 
        case 5: return 30; 
        default: return 5; 
    }
}
    
int getIndex(int porc){
    switch(porc){
        case 5: return 0; 
        case 10: return 1; 
        case 15: return 2; 
        case 20: return 3; 
        case 25: return 4;
        case 30: return 5; 
        default: return 0; 
    }
}
float porcentajeSugerido(){
    switch(jComboBox2.getSelectedIndex()){
        case 1: return 30; 
        case 2: return 50; 
        case 3: return 100; 
        case 4: return 150; 
        case 5: return 200;
        case 6: return 250; 
        case 7: return 300; 
        case 8: return 350; 
        case 9: return 400; 
        case 10: return 450; 
        default: return 20; 
    }
}
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cantidad_distribuidor;
    private javax.swing.JTextField cantidad_mayoreo;
    private javax.swing.JTextField cantidad_medio;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField precio_distribuidor;
    private javax.swing.JTextField precio_mayoreo;
    private javax.swing.JTextField precio_medio;
    private javax.swing.JTextField precio_unitario;
    private javax.swing.JTextField preciocompra;
    // End of variables declaration//GEN-END:variables
}
